package service;

import bean.UrlSave;
import dao.UrlSaveDAO;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;

/**
 * Created by YanYang on 2015/12/28.
 */
@Service("UrlSaveService")
public class UrlSaveService {
    ApplicationContext context = null;

    public boolean tinyUrlSave(long urlID, String normalUrl, String tinyUrl){
        context = new ClassPathXmlApplicationContext("spring-mybatis.xml");

        UrlSaveDAO urlSaveDAO = (UrlSaveDAO)context.getBean("UrlSaveDAO");
        UrlSave urlSave = new UrlSave();
        urlSave.setUrlID(urlID);
        urlSave.setNormalUrl(normalUrl);
        urlSave.setTinyUrl(tinyUrl);
        int bool = urlSaveDAO.tinyUrlSave(urlSave);
        if(bool > 0){
            return true;
        }
        return false;
    }


    public static void main(String[] args){
        UrlSaveService urlSaveService = new UrlSaveService();
        System.out.println(urlSaveService.tinyUrlSave(120,"www.baidu.com","www.xiaoxi.com/1w"));
    }

}
